Skip to content

Syntax change for single cases #7507

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 7, 2019
Merged

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Nov 6, 2019

Allow a single case clause after a match or catch without requiring
braces or indent tokens around it. E.g.

try ...
catch case ex: Ex => ...

s match case p => ...

Ratiionale: With indentation syntax, it feels natural to shorten

try ...
catch
  case ex: Ex => ...

to

try ...
catch case ex: Ex => ...

Allow a single case clause after a match or catch without requiring
braces or indent tokens around it. E.g.

    try ...
    catch case ex: Ex => ...

    s match case p => ...

Ratiionale: With indentation syntax, it feels natural to shorten

    try ...
    catch
      case ex: Ex => ...

to

    try ...
    catch case ex: Ex => ...
Semicolons in match types are not allowed. They were never allowed in syntax.md, but the parser
accepted them. The fix is to just drop the semicolon.
@odersky odersky requested a review from nicolasstucki November 6, 2019 15:25
@odersky odersky assigned nicolasstucki and unassigned odersky Nov 6, 2019
@@ -42,7 +42,7 @@ object Test {
println(identityMaped({ val x: Int | Any = 60; x }))
println(identityMaped({ def f(x: => Int): Int = x; f(61) }))
println(identityMaped({ type T[X] = X; val x: T[Int] = 62; x }))
println(identityMaped({ type T[X] = X match { case Int => String; case String => Int }; val x: T[String] = 63; x }))
println(identityMaped({ type T[X] = X match { case Int => String case String => Int }; val x: T[String] = 63; x }))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the current state of matches without semicolons? We should have neg/pos tests with at least the folowing cases

X match { case Int => String; case String => Int }
X match { case Int => String case String => Int }
x match { case 1 => 3; case 2 => 4 }
x match { case 1 => 3 case 2 => 4 }

@odersky odersky merged commit b5f2f18 into scala:master Nov 7, 2019
@odersky odersky deleted the add-simple-catch branch November 7, 2019 14:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants